package com.ychen.goodscenter.controllers;


import com.ychen.goodscenter.dao.GoodsInfoMapper;
import com.ychen.goodscenter.entity.GoodsInfo;
import com.ychen.usercenter.api.UserInfoFacade;
import com.ychen.usercenter.vo.UserInfoVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;


@RestController
public class GoodsController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final AtomicLong visitCount = new AtomicLong(0);

    @Autowired
    private GoodsInfoMapper goodsInfoMapper;

    @Autowired
    private UserInfoFacade userInfoFacade;

    @GetMapping("/getGoodsDetails")
    public String getGoodsDetails(@RequestParam(value = "goodsId") Long goodsId) {
//        MDC.put("trace_uuid", UUID.randomUUID().toString().replace("-", ""));
//        UserInfoVo userInfo = userCenterFacade.getUserInfoByUserId(2222L);
//        logger.info("userInfo: {}", userInfo.toString());
//        logger.info("visit count: {}", visitCount.incrementAndGet());
        GoodsInfo goodsInfoEntity = goodsInfoMapper.selectByPrimaryKey(goodsId);
        UserInfoVo userInfoVo = userInfoFacade.getUserInfoByUserId(1L);
        return String.format("Hello %s!", goodsInfoEntity.toString()) + userInfoVo.toString();
    }


}
